<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<ul>
    <li>item1</li>
    <li>item2</li>
    <li>item3</li>
    <li>item4</li>
    <li>item5</li>
</ul>

<script>
    var lis = document.getElementsByTagName('li');
    for(var i = 0; i < lis.length;i++ ) {
        lis[i].onclick = function(){alert('you clicked item ' + i);}
    }
</script>
</body>
</html>